<template>
  <mt-loadmore
  :autoFill="false"
  :bottom-method="RequireloadBottom"
  :bottom-all-loaded="allLoaded"
  ref="loadmoreRequire">
    <!-- 需求信息 start -->
    <ul class="content">
      <router-link tag="li" :to="'/require/details/' + list.bid" class="idx-item-box" v-for="(list, key) in requireListData" :key="key">
        <div :class="['idx-warp-l','vm-icon', list.iconClass]"></div>
        <div class="idx-warp-r">
          <div class="idx-r-t">
            <span class="t-type">{{ list.cPOType }}</span>
            <span class="t-time">{{ list.dCenterDate }}</span>
          </div>
          <p class="idx-r-b">{{ list.cIBidsTatle }}</p>
          <div class="idx-r-f">
            <span class="f-area">单位：{{ list.companyName }}</span>
            <span :class="['f-type',list.ClassName]">阶段：{{ list.iRangeStatus }}</span>
          </div>
        </div>
      </router-link>
    </ul>
    <!-- 需求信息 end -->
  </mt-loadmore>
</template>

<script>
  import { getVmIndexRequireData } from '@/api/index.js'
  export default {
    data () {
        return {
          listType: 0, // 0：全部 1：询比价2：竞争性谈判3：单一来源 4:招投标 5：竞价采购
          requireListData: [], // 需求信息列表数据
          allLoaded: false,
          requirePage:0
        }
    },
    created () {
      // 组件间传值
      this.$root.Bus.$on('changeRequireCartgory', type => {
        this.listType = type;
        this.requirePage = 1;
        this.allLoaded = false;
        this.getRequireInfoData(true);
      });
    },
    methods: {
      // 获取需求信息数据
      getRequireInfoData (reset) {
        // reset 是否重置
        getVmIndexRequireData({page: this.requirePage, type: this.listType}).then(async res => {
          if (!res.data.data.length) {
            this.allLoaded = true;
          }
          let resArr = res.data.data.map((item, key, arr) => {
            switch ( item.iRangeStatus ) {
              case '公告期':
                item.ClassName = 'announcementPeriod';
                break;
              case '投标期':
                item.ClassName = 'tender';
                break;
              case '新建':
                item.ClassName = 'create';
                break;
              case '评标期':
                item.ClassName = 'bidEvaluationPeriod';
                break;
              case '结束期':
                item.ClassName = 'end';
                break;
              case '工程设计':
                item.ClassName = 'ed';
                break;
            }
            switch ( item.cPOType ) {
              case '1':
                item.cPOType = '询比价';
                item.iconClass = 'inquiry';
                break;
              case '2':
                item.cPOType = '竞争性谈判';
                item.iconClass = 'competitiveness';
                break;
              case '3':
                item.cPOType = '单一来源';
                item.iconClass = 'singleSource';
                break;
              case '4':
                item.cPOType = '招投标';
                item.iconClass = 'bid';
                break;
              case '5':
                item.cPOType = '竞价采购';
                item.iconClass = 'competitivePrice';
                break;
              default:
                item.cPOType = '其他';
                item.iconClass = 'other';
                break;
            }
            return item;
          });
          if (reset) {
            this.requireListData = resArr;
            // 解决ios无法下拉, 高度距顶部变动bug ; @jiake
            if (this.requirePage == 0) {
              await this.$refs.loadmoreRequire.onBottomLoaded();
              document.getElementsByClassName('vm-index-container')[0].scrollTop = 0;
            };
          } else {
            this.requireListData = this.requireListData.concat(resArr);
            await this.$refs.loadmoreRequire.onBottomLoaded();
          }
        }).catch(err => console.log(err));
      },
      RequireloadBottom () {
        this.requirePage ++;
        this.getRequireInfoData(false);
      },
    },
}
</script>

<style scoped>

</style>
